//
//  NavViewController.m
//  PokerHandUp
//
//  Created by psvn047 on 6/7/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "NavViewController.h"
#import "BaseViewController.h"
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

@interface NavViewController ()
/// Contains view controllers ordered by addition date.
@property (nonatomic, retain) NSMutableArray *mutableViewControllers;
/// Contains view controllers ordered by appearence date.
@property (nonatomic, retain) NSMutableArray *viewControllersQueue;
@property (nonatomic, retain) BaseViewController *topViewController;
@property (nonatomic, retain) UIViewController *topPopupViewController;
@end

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

@implementation NavViewController
@synthesize mutableViewControllers = _mutableViewControllers;
@synthesize viewControllersQueue = _viewControllersQueue;
@synthesize topViewController = _topViewController;
@synthesize topPopupViewController = _topPopupViewController;
-(void) closePopupViewController
{
    if(self.topPopupViewController == nil)
    {
        NSLog(@" nill popup ");
    }
    if(self.topPopupViewController != nil)
    {
        [self.topPopupViewController.view removeFromSuperview];
        self.topPopupViewController = nil;
    }
}
-(void) addTopViewController: (BaseViewController*) viewController;
{
    if(self.topViewController == nil)
    {
        self.topViewController = viewController;
        [self.topViewController show];
    }
    else 
    {
        [self.topViewController.view removeFromSuperview];
        [self.topViewController hide];
        self.topViewController = viewController;
        [self.topViewController show];

    }
    
    [self.view addSubview:self.topViewController.view];
}

-(void) addTopPopupViewController: (UIViewController*) viewController;
{
    if(self.topPopupViewController == nil)
    {
        self.topPopupViewController = viewController;
    }
    else 
    {
        [self.topPopupViewController.view removeFromSuperview];
        self.topPopupViewController = viewController;
    }
    
    [self.view addSubview:self.topPopupViewController.view];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.mutableViewControllers = [NSMutableArray array];
        self.viewControllersQueue = [NSMutableArray array];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.mutableViewControllers = nil;
    self.viewControllersQueue = nil;
    self.topViewController = nil;
    self.topPopupViewController = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
